package A011thread;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;


public class B003_FutureTask例子 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {

        //lam表达式
        FutureTask<Integer> futureTask2 = new FutureTask<>(()->{
            System.out.println(Thread.currentThread().getName()+" come in callable");
            TimeUnit.SECONDS.sleep(3);
            return 1024;
        });

        //创建一个线程
        new Thread(futureTask2,"lucy").start();

        while(!futureTask2.isDone()) {
            System.out.println("正在计算 wait.....");
            TimeUnit.MILLISECONDS.sleep(300);
        }
        //调用FutureTask的get方法
        System.out.println("计算结果 " + futureTask2.get());


        System.out.println(Thread.currentThread().getName()+" come over");
    }
}